﻿package
	{	
	public class Attribute
		{
		var modificator:Array;
		
		public function toString():String
			{
			return modificator.toString();
			}
		
		public function formatAttributes():String
			{
			var stats:String = " ";
			
			for (var i in modificator)
				{
				stats += modificator[i][0] +" : "+ modificator[i][1] +"\n";
				}
			return stats;
			}
		
		public function Attribute (stats:Array)
			{
			modificator = stats;
			}
		
		public function addModificator(stats:Array)
			{
			if (!(stats[0] is Array))
				stats = new Array (stats);
			
			for (var i in stats)
				{
				for (var j:String in modificator)
					{
					if (modificator[j][0].indexOf(stats[i][0])==0)
						{
						modificator[j][1] += stats[i][1];
						break;
						}
					else if (int(j) == modificator.length-1)
						{
						modificator.push(stats[i]);
						break;
						}
					}
				}
			}
		
		public function changeModificator(stats:Array)
			{
			
			}
		
		public function deleteModificator(stats:Array)
			{
			
			}
		
		public function applyModification(player:Player)
			{
			var attribute:Array = player.baseAttributes.modificator;
			for (var i in modificator)
				{
				for (var j in attribute)
					{
					if (attribute[j][0].indexOf(modificator[i][0])==0)
						{
						attribute[j][1] += modificator[i][1];
						break;
						}
					}
				}
			}
			
		public function removeModification(player:Player)
			{
			var attribute:Array = player.baseAttributes.modificator;
			for (var i in modificator)
				{
				for (var j in attribute)
					{
					if (attribute[j][0].indexOf(modificator[i][0])==0)
						{
						attribute[j][1] -= modificator[i][1];
						break;
						}
					}
				}
			}
		
		public function getStat(attribute:String):int
			{
			var stats:Array = this.modificator;
			var value:int = -1;
			
			for (var i in stats)
				{
				if (stats[i][0] == attribute)
					{
					value = stats[i][1];
					break;
					}
				}
			if (value == -1) trace ("Can't get stat "+attribute);
			return value;
			}
		
		}
	}